{-# OPTIONS -fglasgow-exts -fth #-}

import HAppS.Server.State
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as L
import Text.XHtml.Strict hiding (method)
import Views
import Relational
import Types
import Data

newtype XhtmlStrict = XhtmlStrict Text.XHtml.Strict.Html
instance ToMessage XhtmlStrict where
    toContentType _ = B.pack "application/xhtml+xml"
    toMessage (XhtmlStrict html) =
        L.pack $ "<?xml version=\"1.0\"?>\n" ++ renderHtml html

$(systemState ''NoState)

main = do
        control <- startSystemState
        simpleHTTP [dir "en" $ impl English,
                    dir "ru" $ impl Russian,
                    withRequest (\r->
                       notFound $ XhtmlStrict $ pageNotFound English r)
                   ]
        waitForTermination control

impl lang = [method GET $ ok $ XhtmlStrict $ root lang,
        withRequest (\r-> notFound $ XhtmlStrict $ pageNotFound lang r)
    ]
